mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
Loading...
Searching...
No Matches
gc.h
Go to the documentation of this file.
1
6
7#ifndef MRUBY_GC_H
8#define MRUBY_GC_H
9
10#include "common.h"
11
16
17#define MRB_EACH_OBJ_OK 0
18#define MRB_EACH_OBJ_BREAK 1
19typedef int (mrb_each_object_callback)(mrb_state *mrb, struct RBasic *obj, void *data);
20void mrb_objspace_each_objects(mrb_state *mrb, mrb_each_object_callback *callback, void *data);
21size_t mrb_objspace_page_slot_size(void);
22MRB_API void mrb_free_context(mrb_state *mrb, struct mrb_context *c);
23
24#ifndef MRB_GC_ARENA_SIZE
25#define MRB_GC_ARENA_SIZE 100
26#endif
27
28#ifndef MRB_GRAY_STACK_SIZE
29#define MRB_GRAY_STACK_SIZE 1024
30#endif
31
32typedef enum {
33 MRB_GC_STATE_ROOT = 0,
34 MRB_GC_STATE_MARK,
35 MRB_GC_STATE_SWEEP
36} mrb_gc_state;
37
38typedef struct mrb_gc {
39 struct mrb_heap_page *heaps; /* all heaps pages */
40 struct mrb_heap_page *free_heaps;/* heaps for allocation */
41 struct mrb_heap_page *sweeps; /* page where sweep starts */
42 struct mrb_heap_region *regions; /* contiguous heap regions */
43 struct RBasic *gray_stack[MRB_GRAY_STACK_SIZE]; /* stack of gray objects */
44 size_t gray_stack_top; /* top index of gray stack */
45 mrb_bool gray_overflow:1; /* gray stack overflowed; needs heap rescan */
46 size_t live; /* count of live objects */
47 size_t live_after_mark; /* old generation objects */
48 mrb_int gc_debt; /* <0:credit, >0:needs GC */
49 size_t oldgen_threshold; /* threshold to kick major GC */
50 mrb_gc_state state; /* current state of gc */
51 int interval_ratio;
52 int step_ratio;
53 int current_white_part :2; /* make white object by white_part */
54 mrb_bool iterating :1; /* currently iterating over objects */
55 mrb_bool disabled :1; /* GC disabled */
56 mrb_bool generational :1; /* generational GC mode */
57 mrb_bool full :1; /* major GC mode */
58 mrb_bool out_of_memory :1; /* out-of-memory error occurred */
59 size_t step_limit; /* 0=unlimited, >0=absolute step cap */
60 size_t malloc_increase; /* malloc bytes since last GC cycle */
61 size_t malloc_threshold; /* 0=disabled, >0=bytes to trigger GC */
62
63#ifdef MRB_GC_FIXED_ARENA
64 struct RBasic *arena[MRB_GC_ARENA_SIZE]; /* GC protection array */
65#else
66 struct RBasic **arena; /* GC protection array */
67 int arena_capa; /* size of protection array */
68#endif
69 int arena_idx;
70
71#ifdef MRB_GC_STATS
72 uint32_t gc_total_count; /* total GC invocations */
73 uint32_t minor_gc_count; /* minor GC count */
74 uint32_t major_gc_count; /* major GC count */
75#endif
76} mrb_gc;
77
78MRB_API mrb_bool mrb_object_dead_p(mrb_state *mrb, struct RBasic *object);
79MRB_API int mrb_gc_add_region(mrb_state *mrb, void *start, size_t size);
80
81#define MRB_GC_RED 7
82
84
85#endif /* MRUBY_GC_H */
mruby common platform definition"
#define MRB_END_DECL
End declarations in C mode.
Definition common.h:28
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition common.h:26
#define MRB_API
Declare a public mruby API function.
Definition common.h:108
Definition object.h:19
Definition mruby.h:196
Definition gc.h:38
Definition gc.c:169
Definition gc.c:178
Definition mruby.h:280